/**
 * @file lv_battery.h
 *
 */

#ifndef LV_BATTERY_H
#define LV_BATTERY_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/
#include "../../../lvgl/src/core/lv_obj.h"

#if LV_USE_BATTERY

/*********************
 *      DEFINES
 *********************/

#ifndef LV_BATTERY_LEVEL
    #define LV_BATTERY_LEVEL      5  /**<level of color for battery charge and discharge*/
#endif

/**********************
 *      TYPEDEFS
 **********************/

typedef enum {
    LV_BATTERY_DIR_LEFT = 0, /**<Positive direction is left*/
    LV_BATTERY_DIR_RIGHT,    /**<Positive direction is right*/
    LV_BATTERY_DIR_TOP,      /**<Positive direction is top*/
    LV_BATTERY_DIR_BOTTOM,   /**<Positive direction is bottom*/
} lv_battery_dir_t;

typedef enum {
    LV_BATTERY_FLASH_NULL =    (1 << 0), /**<*Flashing when discharg null*/
    LV_BATTERY_FLASH_FULL =    (1 << 1), /**<*Flashing when fully charged*/
    LV_BATTERY_UP_CHARGING =   (1 << 2), /**<*Color for upward charging*/

    LV_BATTERY_DIS_DYNC_COLOR = (1 << 6), /**<* disable color indication*/
    LV_BATTERY_DIS_POSITIVE =   (1 << 7), /**<* disable positive indication*/
} lv_battery_dync_t;

typedef struct{
    uint16_t len;            /*Pixel of the length direction*/
    uint16_t diam;           /*diam of the length direction*/
    uint8_t  radius_size;     /* radius size, 0 without radius*/
    lv_opa_t opa;            /* transparency*/
    uint32_t color;          /* Overall color*/
    const lv_style_t *style; /*under painting, rect color etc. NULL use default*/
} lv_battery_basemap_t;

typedef struct{
     /*attribute*/
    uint8_t border_size;            /*main border rect size*/
    uint8_t pad_size;               /*fill in boundary size*/
    lv_opa_t null_opa;              /* Transparency of unfilled areas*/
    lv_opa_t full_opa;              /* Transparency of filled areas*/
    uint32_t null_color;            /* color of unfilled areas*/
    uint32_t full_color;            /* color of filled areas (when color indication is prohibited)*/
    /*Level color indication*/
    uint8_t  charge_pct_level[LV_BATTERY_LEVEL];    /*percentage of charging critical point,0-100*/ 
    uint8_t  discharge_pct_level[LV_BATTERY_LEVEL]; /*percentage of discharging critical point,0-100*/
    uint8_t  pct_backlash;          /*Charging or discharging percentage hysteresis,0-100*/  
    uint32_t charge_color[LV_BATTERY_LEVEL];        /*charging color indicator,high as much*/ 
    uint32_t discharge_color[LV_BATTERY_LEVEL];     /*discharge color indicator,high as much*/ 
} lv_battery_fill_t;

typedef struct{
    lv_battery_dync_t dync;        /*Dynamic indication of battery status*/
    uint16_t space_positive_main;   /*The distance between positive and negative*/    
    uint8_t pct_accuracy;           /*percentage accuracy,0:0~100,1:0.0~100.0 2:0.00~100.00*/
    const lv_font_t * pct_font;    /*battery percentage, NULL is no battery indicator*/
    lv_battery_basemap_t positive; /*Description of positive base map*/
    lv_battery_basemap_t main;     /*Description of main body base map*/
    lv_battery_fill_t    fill;     /*Description of main body pattern filling*/
}lv_battery_cfg_t;

LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_battery_class;
/**********************
 * GLOBAL PROTOTYPES
 **********************/

/**
 * Create a battery object,The next step is to call lv_battery_set_cfg() for configuration
 * @param parent    pointer to an object, it will be the parent of the new battery
 * @param cfg       battery symbol configuration, NULL is the default small icon
 * @return          pointer to the created battery
 */
lv_obj_t * lv_battery_create(lv_obj_t * parent);

/**
 * set config
 * @param obj     pointer to a battery
 * @param cfg     must be statically maintained, Use default config when NULL
 */
void lv_battery_set_cfg(lv_obj_t * obj, const lv_battery_cfg_t *cfg);

/**
 * set dir
 * @param obj     pointer to a battery
 * @param dir     Direction of battery pattern
 */
void lv_battery_set_dir(lv_obj_t * obj, lv_battery_dir_t dir);

/**
 * Update battery electricity percentage
 * @param obj     pointer to a battery
 * @param percent electricity percentage, positive charging negative discharging 
 */
void lv_battery_update_percent(lv_obj_t * obj, int32_t pct);

/**
 * get the current configuration
 * @param obj   pointer to a battery
 * @return      lv_battery_cfg_t
 */
const lv_battery_cfg_t *lv_battery_get_cfg(lv_obj_t * obj);

/**
 * get battery level accuracy
 * @param obj   pointer to a battery
 * @return      accuracy: 0:0~100, 1:0.0~100.0  2:0.00~100.00
 */
int8_t lv_battery_get_percent_accuracy(lv_obj_t * obj);

/**
 * get battery electricity percentage
 * @param obj   pointer to a battery
 * @return      electricity percentage, positive charging negative discharging 
 */
int32_t lv_battery_get_percent(lv_obj_t * obj);

/**********************
 *      MACROS
 **********************/

#endif /*LV_USE_BATTERY*/

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*LV_BATTERY_H*/
